package com.practice;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class CallableTest implements Callable {
    @Override
    public Object call() throws Exception {
//        int sum =0;
//        for (int i = 0; i < 100; i++) {
//            sum += i;
//        }
//        return sum;
        return null;
    }

    public static void main(String[] args) {
        CallableTest callable =new CallableTest();
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        FutureTask<Integer> futureTask1 = new FutureTask<>(() -> {
            int sum = 0;
            for (int i = 1; i < 101; i++) {
                sum += i;
            }
            return sum;
        });
        Thread thread =new Thread(futureTask1);
        thread.start();
        try {
            System.out.println(futureTask1.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < 1000; i++) {
            System.out.println("main运行" + i + "次");
        }
    }
}
